package com.fp.m7.repository;

import java.util.Set;

import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.GraphRepository;

import com.fp.m7.model.Account;
import com.fp.m7.model.Follow;

public interface FollowRepository extends GraphRepository<Follow> {

	@Query(value = "start srcAccount=node({0}), destAccount=node({1})" + //
			" match srcAccount-[f:FOLLOWS]->followed" + //
			" where followed = destAccount and f.auditDD? is null" + //
			" return f", elementClass = Follow.class)
	Set<Follow> isFollowing(Account user, Account other);

	@Query(value = "start account=node({0})" + //
			" match account<-[f:FOLLOWS]-followed" + //
			" where f.auditDD? is null" + //
			" return followed", elementClass = Account.class)
	Set<Account> getFollowersForUser(Account user);

	@Query(value = "start account=node({0})" + //
			" match account-[f:FOLLOWS]->followed" + //
			" where f.auditDD? is null" + //
			" return followed", elementClass = Account.class)
	Set<Account> getFollowedByUser(Account user);

	@Query("start account=node({0})" + //
			" match account<-[f:FOLLOWS]-followed" + //
			" where f.auditDD? is null" + //
			" return count(*)")
	Long countActiveFollowers(Account followed);

	@Query("start account=node({0})" + //
			" match account-[f:FOLLOWS]->followed" + //
			" where f.auditDD? is null" + //
			" return count(followed)")
	Long countActivelyFollowed(Account follower);
}
